/**
 * Project: apollo-base-tools
 * 
 * File Created at 2017年8月1日
 * 
 * Copyright 2015-2016 dx.com Croporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DongXue software Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with dx.com.
 */
package org.apollo.base.tools.ui.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.Icon;
import javax.swing.JComponent;

/**
 * @ClassName: LayerButton
 * @Description: 层按钮
 * @author wuzhenfang(wzfbj2008@163.com)
 * @date 2017年8月1日 下午5:18:22
 * @version V1.0
 */
public class LayerButton extends JComponent {

	private static final long serialVersionUID = -1966994437245413752L;

	private ArrayList<ActionListener> listeners = new ArrayList<ActionListener>();

	private String text;

	private Icon icon;

	private float alignment = LEFT_ALIGNMENT;

	public LayerButton() {
		this(null, null);
	}

	public LayerButton(String text, Icon icon) {
		this.text = text;
		this.icon = icon;
		updateUI();
	}

	public void addActionListener(ActionListener listener) {
		if (!listeners.contains(listener))
			listeners.add(listener);
	}

	public void removeActionListener(ActionListener listener) {
		if (listeners.contains(listener))
			listeners.remove(listener);
	}

	protected void fireActionPerformed(ActionEvent e) {
		for (ActionListener listener : listeners) {
			listener.actionPerformed(e);
		}
	}

	public void setText(String text) {
		this.text = text;
		repaint();
	}

	public String getText() {
		return text;
	}

	public Icon getIcon() {
		return icon;
	}

	public void setIcon(Icon icon) {
		this.icon = icon;
		repaint();
	}

	public float getAlignment() {
		return alignment;
	}

	public void setAlignment(float alignment) {
		this.alignment = alignment;
		repaint();
	}

	public void updateUI() {
		setUI(new LayerButtonUI());
	}
}
